using System.Collections.Generic;
using Admin3000.Backend.Api.Entity;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace Admin3000.Backend.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UsersController : ControllerBase
    {
        [HttpGet]
        public dynamic Get()
        {
            var users=GetUsers();
            return users;
        }

        [HttpGet("{id}")]
        public dynamic Get(int id)
        {
            var users=GetUsers();
            var user=users.Where(x=>x.Id==id).FirstOrDefault();
            return user;
        }

        [HttpPost]
        public dynamic Post(dynamic model){


            return new {
                Code=1000,
                Data=model,
                Msg="创建用户成功"
            };
        }

        [HttpPut("{id}")]
        public dynamic Put(int id,dynamic model){
            

            return new {
                Code=1000,
                Data =model,
                Msg =string.Format("你修改的用户的id为：{0}，已经修改成功，请注意查收",id)
            };
        }

        [HttpDelete("{id}")]
        public dynamic Delete(int id){
            return new {
                Code =1000,
                Msg =string.Format("删除指定id为{0}的用户成功",id)
            };
        }

        private IEnumerable<Users> GetUsers()
        {
            var users =
                new List<Users> {
                    new Users {
                        Id = 1,
                        Username = "admin",
                        Password = "芝麻开门"
                    },
                    new Users {
                        Id = 2,
                        Username = "超级管理员",
                        Password = "芝麻开门"
                    },
                    new Users {
                        Id = 3,
                        Username = "普通用户",
                        Password = "芝麻开门"
                    }
                };

            return users;
        }
    }
}
